<template>
    <div class="my">
<!--        <formHeader :title="'我的'"></formHeader>-->
        <div class="headers">
            <users :user="user" :account="account" :level="extra.level.name" :topMobile="extra.mobile"></users>
            <userAttention></userAttention>
            <userAgency :exp="extra.exp"></userAgency>
        </div>
        <div class="con">
            <div class="control">
                <div class="left single">
                    <div v-if="index !== 1 "  class="controlItem" v-for="(item,index) in wallet" :key="index"  @click="turn(item.path)">
                        <span class="num">{{item.num?item.num:0}}</span>
                        <span class="name">{{item.name}}</span>
                    </div>
                </div>
                <div class="right">
                    <div class="device"><img src="./image/device.png"></div>
                    <div class="controlItem" @click="turn(`/wallet?money=${wallet[0].num}`)">
                        <span><img src="./image/wallet.png"></span>
                        <span class="name">我的钱包</span>
                    </div>
                </div>
            </div>
            <div class="control">
                <div class="left">
                    <div @click="turn(item.path)" class="controlItem" v-for="(item,index) in earn" :key="index">
                        <span class="num">{{item.num?item.num:0}}</span>
                        <span class="name">{{item.name}}</span>
                    </div>
                </div>
                <div class="right">
                    <div class="device"><img src="./image/device.png"></div>
                    <div class="controlItem" @click="turn()">
                        <span><img src="./image/earn.png"></span>
                        <span class="name">我的利润</span>
                    </div>
                </div>
            </div>
            <div class="control">
                <div class="left">
                    <div class="controlItem" v-for="(item,index) in inventory" :key="index" @click="turn(item.path)">
                        <span><img :src="item.img"></span>
                        <span class="name">{{item.name}}</span>
                    </div>
                </div>
                <div class="right">
                    <div class="device"><img src="./image/device.png"></div>
                    <div class="controlItem">
                        <span><img src="./image/guanli.png" @click="turn()"></span>
                        <span class="name">库存管理</span>
                    </div>
                </div>
            </div>
            <div class="control">
                <div class="left">
                    <div class="controlItem" v-for="(item,index) in order" :key="index" @click="turn(item.path)">
                        <span><img :src="item.img"></span>
                        <span class="name">{{item.name}}</span>
                    </div>
                </div>
                <div class="right">
                    <div class="device"><img src="./image/device.png"></div>
                    <div class="controlItem" @click="turn('neworder?type=0')">
                        <span><img src="./image/shouhou.png"></span>
                        <span class="name" >我的订单</span>
                    </div>
                </div>
            </div>
            <userServe :title="'我的服务'" :serve="serve" isImg></userServe>
<!--            <userServe :title="'短视频'" :serve="video"></userServe>-->
            <div class="shopTitle" v-if="this.shopInfo.shop&&this.shopInfo.shop.status==1">我的店铺</div>
            <div class="shop" v-if="this.shopInfo.shop&&this.shopInfo.shop.status==1">
                <userShop
                        :nowOrderNum="shopInfo.nowOrderNum"
                        :shopInfo="shopInfo.shop"
                        :nowPrice="shopInfo.nowPrice"
                        :totalOrderNum="shopInfo.totalOrderNum"
                        :totalPrice="shopInfo.totalPrice"
                        :totalIncome="shopInfo.totalIncome"
                        :downIncome="shopInfo.downIncome"
                ></userShop>
                <shopBtn></shopBtn>
            </div>
        </div>
    </div>
</template>

<script>
    import formHeader from '@/components/form-header'
    import users from '@/components/users'
    import userAttention from '@/components/users/userAttention'
    import userAgency from '@/components/users/userAgency'
    import userServe from '@/components/users/userServe'
    import userShop from '@/components/users/user-shop'
    import shopBtn from '@/components/users/shop-btn'
    import {info,skipToSjyx,getProfits,getShopInfo} from "../../api/user"
    import {showError} from '@/toast'
    import *  as Dialog from '@/dialog'
    export default {
        name : "newmy",
        components:{formHeader,users,userAttention,userAgency,userServe,userShop,shopBtn},
        data(){
            return{
                wallet:[
                    {name:'代金券',num:0,path:'/wallet/detail?type=0'},
                    {name:'积分',num:0,path:'/wallet/detail?type=1'},
                    {name:'优惠券',num:0,path:'/wallet/detail?type=2'},
                    {name:'换购券',num:0,path:'/wallet/detail?type=3'},
                    {name:'待收款',num:0,path:'wallet/collected'},
                    {name:'清货券',num:0,path:'/wallet/detail?type=6'},
                    {name:'公益金',num:0,path:'/wallet/detail?type=7'},
                    {name:'换购卡',num:0,path:'/account/card'},
                ],
                earn:[
                    {name:'代理有利',num:0,path:'/earn?type=0'},
                    {name:'分享有利',num:0,path:'/earn?type=1'},
                    {name:'换购有利',num:0,path:'/earn?type=2'},
                    {name:'店铺有利',num:0,path:'/earn?type=8'},
                    {name:'服务有利',num:0,path:'/earn?type=9'}
                ],
                inventory:[
                    {name:'库存明细',img:require('./image/kucun.png'),path:'/store'},
                    {name:'申请发货',img:require('./image/fahuo.png'),path:'/repertory?type=0'},
                    {name:'申请转货',img:require('./image/zhuanhuo.png'),path:'/repertory?type=1'},
                    {name:'退换/售后',img:require('./image/tuihuan.png'),path:''},
                ],
                order:[
                    {name:'待付款',img:require('./image/daifukuan.png'),path:'/neworder?type=1'},
                    {name:'待收货',img:require('./image/daishou.png'),path:'/neworder?type=2'},
                    {name:'团购订单',img:require('./image/daishou.png'),path:'/shareOrder?type=0'},
                    {name:'分享订单',img:require('./image/daishou.png'),path:'/shareOrder?type=1'},
                    {name:'待评价',img:require('./image/pingjia.png'),path:''},
                    {name:'退换/售后',img:require('./image/dingdan.png'),path:''},
                ],
                serve:[
                    {name:'我的好友',img:require('@/components/users/image/friend.png'),path:'/user'},
                    {name:'邀请好友',img:require('@/components/users/image/yaoqing.png'),path:'/share'},
                    {name:'地址管理',img:require('@/components/users/image/dizhi.png'),path:'/address'},
                    {name:'平台客服',img:require('@/components/users/image/kefu.png'),path:'tel'},
                    {name:'申请开店',img:require('@/components/users/image/openShop.png'),path:'open'},
                    {name:'我的授权',img:require('@/components/users/image/yijian.png'),path:'/grant'},
                    {name:'分享销冠',img:require('@/components/users/image/fxxg.png'),path:'/month?team=0'},
                    {name:'复购销冠',img:require('@/components/users/image/fgxg.png'),path:'/month'}
                    // {name:'设置',img:require('@/components/users/image/setting.png'),path:''},
                ],
                video:[
                    {name:'我的发布',num:0,path:''},
                    {name:'我的收藏',num:0,path:''},
                    {name:'草稿箱',num:0,path:''},
                    {name:'我的关注',num:0,path:''},
                    {name:'我的分析',num:0,path:''},
                    {name:'获赞',num:0,path:''},
                ],
                user:{},
                extra:{
                    level:{
                        name:''
                    }
                },
                account:[],
                shopInfo:{}


            }
        },
        methods:{
            turn(path){

                if(!path){
                    return
                }
                this.$router.push({
                    path:path
                })
            }

        },
        activated(){
            info().then(res=>{
                this.user = res.data
                this.extra = res.extra
                this.account = res.extra.accounts
                this.wallet[7].num = res.extra.coupons.length+'张'
                // if(!this.user.mobile){
                //     this.$createDialog({
                //         type: 'confirm',
                //         icon: 'cubeic-alert',
                //         content: '请绑定手机号码',
                //         confirmBtn: {
                //             text: '去绑定',
                //             active: true,
                //             disabled: false,
                //             href: 'javascript:;'
                //         },
                //         cancelBtn: {
                //             text: '再看看',
                //             active: false,
                //             disabled: false,
                //             href: 'javascript:;'
                //         },
                //         onConfirm: () => {
                //             this.$router.push({
                //                 path:'/my/edit',
                //                 query:{
                //                     name:this.user.name,
                //                     mobile:this.user.mobile,
                //                     back:true
                //                 }
                //             })
                //         }
                //     }).show()
                // }
                if(this.account){
                    this.account.forEach(item=>{
                        if(item.type==0){
                            this.wallet[0].num=item.amount
                        }
                        // if(item.type==1){
                        //     this.wallet[1].num=item.amount
                        // }
                        if(item.type==2){
                            this.wallet[2].num=item.amount
                        }
                        if(item.type==3){
                            this.wallet[3].num=item.amount
                        }
                        if (item.type==6){
                            this.wallet[5].num=item.amount
                        }
                        if (item.type==7){
                            this.wallet[6].num=item.amount
                        }
                    })
                }
                this.wallet[4].num=this.extra.waitIncome
            })
            getShopInfo().then(res=>{
                this.shopInfo = res.extra
            })
            getProfits().then(res=>{
                let data = Object.values(res.data)
                data.forEach((item,index)=>{
                    this.earn[index].num = item
                })
            })
        }
    }

</script>

<style scoped lang="stylus">
.my
    .headers
        position relative
        height 180px
        /*margin-top 46px*/
        padding-left 15px
        background url("./headbg.png") no-repeat
        background-size 375px 180px
    .con
        padding-bottom 100px
        .control
            display flex
            justify-content center
            padding 20px 28px
            background-color #fff
            margin-top 10px
            font-size 11px
            font-weight 200
            color #666666
            .left,.right
                display flex
                justify-content space-between
                align-items center
                flex-wrap wrap
                .controlItem
                    display flex
                    flex 25%
                    flex-direction column
                    justify-content space-between
                    align-items center
                    height 47px
                    .num
                        color #333
                        font-size 15px
                        font-family DIN
                        padding-top 9px
                        font-weight 400
                    img
                        width 30px
                        height 30px
            .left
                flex 1
                display flex
                justify-content flex-start
                padding-right 15px
                .controlItem
                    flex 0 0 25%
            .single
                /*flex-wrap nowrap!important*/
                flex 25%

            .right
                width 58px
                flex-wrap nowrap
                .name
                    white-space nowrap
                .device
                    img
                        height 45px
        .shopTitle
            background-color: #fff
            color #333
            font-weight bold
            font-size  13px
            padding 10px
            margin-top 10px
            border-bottom 1px solid #EEEEEE
        .shop
            background-color: #fff
            padding 0 15px


</style>
